/**
 * Created by shenhai on 15/9/5.
 */


angular.module('mis.communityManager.controllers', [])
    .controller('communityCtrl', ['$scope','$http', '$location', function ($scope, $http, $location) {


        $scope.currentPage = 1;
        $scope.pageSize = 10;
        //绑定一个错误的小区城市ID，缩短响应时间
        var params = {valid:true,city:'549968e5bc537bb017132f01'};

        //小区分页
        $scope.pagination = new pagination({currentPage:$scope.currentPage,pageSize: $scope.pageSize,
            url:'http://' + backOfficeHost + '/rest/v1.0/mis/community/communityList/:page/:size',
            ajax: $http,
            success:function(data){
                $scope.communityList = data.data.list;
                $scope.pageNumber = data.data.totalPage;
                $scope.count = data.data.count;
                $scope.communityList.forEach(function(community){
                    if (community.communityLogo) {
                        community.communityLogo = fastDfsHostIp + community.communityLogo
                    };
                });
                $scope.currentPage = $(".am-active").text();
                $scope.pagination.totalPage = data.data.totalPage;
                $scope.pagination.pageHeader($scope.pageNumber);
                $('#count').text("共"+$scope.pageNumber+"页 有"+$scope.count+"数据");
            },
            error: function(err){
                $scope.communityList = null;
            },
            params: params
        });

        //全选列表
        $scope.allSelected = function () {
            $scope.pagination.allSelected();
        };

        //搜索
        $scope.search = function (temp) {

            var btn = temp.target;
            $scope.pagination.currentPage = 1;
            $scope.currentPage = 1;
            var city = $scope.cascading.getCity(btn);
            var community = $scope.cascading.getVillageId(btn);
            var communityName = $scope.cascading.getVillage(btn);
            var desc = $scope.cascading.getVillage(btn);

            var body = {};
            if (city) body.city = city;
            if (community) body.id = community;
            if (communityName) body.communityName = communityName;
            if (desc) body.communityName = desc;

            if ($scope.valid) body.valid = $scope.valid;
            if ($scope.init) body.init = $scope.init;

            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/community/communityList/' + $scope.currentPage + '/' + $scope.pageSize, body, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {
                $scope.communityList = data.data.list;
                $scope.pageNumber = data.data.totalPage;
                $scope.count = data.data.count;
                $scope.communityList.forEach(function(community) {
                    if (community.communityLogo) {
                        community.communityLogo = fastDfsHostIp + community.communityLogo
                    };
                });
                $scope.pagination.totalPage = data.data.totalPage;
                $scope.pagination.pageHeader($scope.pageNumber);
                $scope.pagination.searchParams = body;
            }).error(function (err) {
                $scope.communityList = [];
                alert(err);
            });

        };

        $scope.addCommunity = function() {
            $scope.cascading.paint($("#cascad-search-add")[0],false);
        };


        //新增
        $scope.add = function(addData, temp){

            var target = temp.target;

            var provinceId = $scope.cascading.getProvince (target);
            var cityId = $scope.cascading.getCity (target);
            var countyId = $scope.cascading.getCityArea (target);
            var city = $scope.cascading.getCityVal (target);

            //if (!(provinceId && cityId && countyId && city && addData.communityName && addData.communityAddress && addData.longitude && addData.latitude)) {
            //    alert("缺少小区基础数据");
            //    return;
            //}
            //if(!provinceId || !cityId || !countyId || !city || !addData.communityName || !addData.communityAddress || !addData.longitude || !addData.latitude)
            //{
            //    alert("缺少小区基础数据");
            //    return;
            //}
            //var fd = $scope.image ? (new FormData()):{};
            //
            //if (provinceId) fd.provinceId = provinceId;
            //if (cityId) fd.cityId = cityId;
            //if (countyId) fd.countyId = countyId;
            //if (city) fd.city = city;
            //for(var key in addData) {
            //    if (addData[key]) fd[key] = addData[key];
            //}
            //if ($scope.image)  fd.append('image1', $scope.image);
            var opt ={};
            if (provinceId) {opt.provinceId = provinceId }else { alert('请填写小区所在省市区!');return};
            if (cityId) {opt.cityId = cityId }else { alert('请填写小区所在省市区!');return};
            if (countyId) {opt.countyId = countyId }else { alert('请填写小区所在省市区!');return};
            if (city) {opt.city = city }else { alert('请填写小区所在省市区!');return};
            if (addData.communityName) {opt.communityName = addData.communityName }else { alert('请填写小区名称!');return};
            if (addData.communityAddress) {opt.communityAddress = addData.communityAddress }else { alert('请填写小区地址!');return};
            if (addData.longitude) {opt.longitude = addData.longitude }else { alert('请填写小区经纬度!');return};
            if (addData.latitude) {opt.latitude = addData.latitude }else { alert('请填写小区经纬度!');return};
            if (addData.communityPostCode) {opt.communityPostCode = addData.communityPostCode};
            //if (addData.dateEffective) {opt.dateEffective = addData.dateEffective };
            if (addData.households) {opt.households = addData.households };
            if (addData.unitSwitch) {opt.unitSwitch = addData.unitSwitch };

            if (addData.developer) opt.developer = addData.developer;
            if (addData.propertyType) opt.propertyType = addData.propertyType;
            if (addData.property) opt.property = addData.property;
            if (addData.price) opt.price = addData.price;
            opt.dateBuild = $("#dateBuild-add").val();


            if ($scope.image != null) {

                var fd = new FormData();
                fd.append('image1', $scope.image);
                //上传图片
                $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/common/uploadImage', fd, {
                    transformRequest: angular.identity,
                    headers: {'Content-Type': undefined}
                }).success(function (images) {
                    opt.communityLogo = images.data[0];
                    //console.debug(opt);
                    $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/community/communityAdd', opt,{
                        headers: {'Content-Type': 'application/json;charset=utf-8'}
                    }).success(function (data) {
                        $('#doc-modal-add').modal("close");
                        if(data.result.status == 1) {
                            //$scope.addData = {};
                            $scope.pagination.selectPage(1);//插入成功显示第一页
                            alert("添加小区成功");
                        }else{
                            alert(data.result.message);
                        };
                    }).error(function (err) {
                        alert(err);
                    });

                }).error(function (err) {
                    alert('图片上传失败!');
                    logger.debug(err);
            });

            }else{
                //console.debug(opt);
                $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/community/communityAdd', opt,{
                    headers: {'Content-Type': 'application/json;charset=utf-8'}
                }).success(function (data) {
                    $('#doc-modal-add').modal("close");
                    if(data.result.status == 1) {
                        //$scope.addData = {};
                        $scope.pagination.selectPage(1);//插入成功显示第一页
                        alert("添加小区成功");
                    }else{
                        alert(data.result.message);
                    }
                }).error(function (err) {
                    alert(err);
                });

            };



            //var header = $scope.image ?
            //{transformRequest: angular.identity, headers: {'Content-Type': undefined}} :
            //{headers: {'Content-Type': 'application/json;charset=utf-8'}};
            //
            //$http.post('http://' + backOfficeHost + '/rest/v1.0/mis/community/communityAdd', fd, header).success(function (data) {
            //
            //    $scope.pagination.selectPage(1);//插入成功显示第一页
            //    $('#doc-modal-add').modal("close");
            //    alert("添加小区成功");
            //    addData ={};
            //}).error(function (err) {
            //    alert(err);
            //});

        };


        $scope.editClick = function(listData,index){

            $scope.cascading.paint($("#cascad-edit")[0],false);

            if(listData.provinceId)$("#cascad-edit").find(".c-provinces").val(listData.provinceId.name);
            if(listData.provinceId)$("#cascad-edit").find(".c-provinces")[0].dataset.cId = listData.provinceId.objId;
            if(listData.cityId)$("#cascad-edit").find(".c-citys").val(listData.cityId.name);
            if(listData.cityId)$("#cascad-edit").find(".c-citys")[0].dataset.cId = listData.cityId.objId;
            if(listData.countyId) {
                $("#cascad-edit").find(".c-cityArea").val(listData.countyId.name);
                if (listData.countyId)$("#cascad-edit").find(".c-cityArea")[0].dataset.cId = listData.countyId.objId;
            }

            $('#doc-modal-edit').modal({target: '#doc-modal-edit', width: 800, height: 600});
            if(listData.dateBuild) listData.dateBuild = (new Date(listData.dateBuild)).format('yyyy-MM-dd');
            $scope.updateData  = listData;


        };

        //编辑
        $scope.update = function(updateData, temp, index) {
            var target = temp.target;

            var provinceId = $("#cascad-edit").find(".c-provinces")[0].dataset.cId;
            var cityId = $("#cascad-edit").find(".c-citys")[0].dataset.cId;
            var city = $("#cascad-edit").find(".c-citys").val();
            var countyId = $("#cascad-edit").find(".c-cityArea")[0].dataset.cId;



            //if (!(provinceId && cityId && countyId && city && addData && addData.communityName && addData.communityAddress)) {
            //    alert("缺少小区基础数据");
            //    return;
            //}
            //
            //var fd = $scope.image ? (new FormData()):{};
            //fd.id = addData.objId;
            //if (provinceId) fd.provinceId = provinceId;
            //if (cityId) fd.cityId = cityId;
            //if (countyId) fd.countyId = countyId;
            //if (city) fd.city = city;
            //if (addData.communityName) fd.communityName = addData.communityName;
            //if (addData.communityAddress) fd.communityAddress = addData.communityAddress;
            //if (addData.dateEffective) fd.dateEffective = addData.dateEffective;
            //if (addData.households) fd.households = addData.households;
            //if (addData.communityPostCode) fd.communityPostCode = addData.communityPostCode;
            //if (addData.phoneList && addData.phoneList.length) fd.phoneList = addData.phoneList;
            //fd.unitSwitch = addData.unitSwitch;
            //if ($scope.image)  fd.append('image1', $scope.image);
            //
            //
            //var header = $scope.image ?
            //{transformRequest: angular.identity, headers: {'Content-Type': undefined}} :
            //{headers: {'Content-Type': 'application/json;charset=utf-8'}};

            var opt ={id : updateData.objId};
            //if (provinceId) {opt.provinceId = provinceId }else { alert('请填写小区所在省市区!');return};
            if (cityId) {opt.cityId = cityId }else { alert('请填写小区所在省市区!');return};
            //if (countyId) {opt.countyId = countyId }else { alert('请填写小区所在省市区!');return};
            if (city) {opt.city = city };
            if (updateData.communityName) {opt.communityName = updateData.communityName }else { alert('请填写小区名称!');return};
            if (updateData.communityAddress) {opt.communityAddress = updateData.communityAddress }else { alert('请填写小区地址!');return};
            if (updateData.location.longitude) {opt.location = updateData.location}else { alert('请填写小区经纬度!');return};
            if (updateData.location.latitude) {opt.location = updateData.location }else { alert('请填写小区经纬度!');return};

            if (updateData.communityPostCode) {opt.communityPostCode = updateData.communityPostCode};
            //if (updateData.dateEffective) {opt.dateEffective = updateData.dateEffective };
            if (updateData.households) {opt.households = updateData.households };
            //if (updateData.unitSwitch) {opt.unitSwitch = updateData.unitSwitch };
            opt.unitSwitch = updateData.unitSwitch;

            if (updateData.phoneList && updateData.phoneList.length) opt.phoneList = updateData.phoneList;


            if (updateData.developer) opt.developer = updateData.developer;
            if (updateData.propertyType) opt.propertyType = updateData.propertyType;
            if (updateData.property) opt.property = updateData.property;
            if (updateData.price) opt.price = updateData.price;
            opt.dateBuild = $("#dateBuild").val();
            //if (updateData.dateBuild) opt.dateBuild = updateData.dateBuild;
            //(new Date(updateData.dateBuild)).format('yyyy-MM-dd hh:mm')
            console.debug(opt);
            if ($scope.image != null) {

                var fd = new FormData();
                fd.append('image1', $scope.image);
                //上传图片
                $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/common/uploadImage', fd, {
                    transformRequest: angular.identity,
                    headers: {'Content-Type': undefined}
                }).success(function (images) {
                    opt.communityLogo = images.data[0];
                    $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/community/communityEdit', opt, {
                        headers: {'Content-Type': 'application/json;charset=utf-8'}
                    }).success(function (data) {

                        if (data.result.status == 1) {
                            $('#doc-modal-edit').modal("close");
                            alert("编辑小区成功");
                            $scope.pagination.selectPage(1);//插入成功显示第一页
                        } else {
                            alert("编辑小区失败");
                            $scope.pagination.selectPage($scope.currentPage);
                        };

                    }).error(function (err) {
                        alert("编辑小区失败");
                        $scope.pagination.selectPage($scope.currentPage);
                    });
                }).error(function (err) {
                    alert('图片上传失败!');
                    logger.debug(err);
                });

            }else{

                $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/community/communityEdit', opt, {
                    headers: {'Content-Type': 'application/json;charset=utf-8'}
                }).success(function (data) {

                    if (data.result.status == 1) {
                        $('#doc-modal-edit').modal("close");
                        alert("编辑小区成功");
                    } else {
                        alert("编辑小区失败");
                        $scope.pagination.selectPage($scope.currentPage);
                    };

                }).error(function (err) {
                    alert("编辑小区失败");
                    $scope.pagination.selectPage($scope.currentPage);
                });

            };

        };



        $scope.addPhoneNo = function (community) {
            var temp = {
                "name": "",
                "phoneNo": "",
                "address": ""
            };
            community.phoneList.push(temp);
        };

        $scope.deletePhoneNo = function (community, index) {
            community.phoneList.remove(index);
        };

        Array.prototype.remove = function (dx) {
            if (isNaN(dx) || dx > this.length) {
                return false;
            }
            for (var i = 0, n = 0; i < this.length; i++) {
                if (this[i] != this[dx]) {
                    this[n++] = this[i]
                }
            }
            this.length -= 1
        };

        $scope.selectFile = function (files) {
            $scope.image = files[0];

            var reader = null;
            if (FileReader) {
                reader = new FileReader();
            } else {
                alert("浏览器暂时不支持FileReader");
            }

            reader.readAsDataURL(files[0]);
            reader.onload = function () {
                $('#logo').attr("src", reader.result);
            };
        };

        $scope.openCommunity = function(community) {
            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/community/communitySwitch', {id:community.objId,isValid:true}, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {
                community.isValid = true;
            }).error(function () {
            });
        };

        $scope.closeCommunity = function(community) {
            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/community/communitySwitch', {id:community.objId,isValid:false}, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {
                community.isValid = false;
            }).error(function () {
            });
        };

        $scope.exportCommunity = function() {

        };



        //级联框
        var cascadData = {
            provinceUrl: 'http://' + backOfficeHost + '/rest/v1.0/backoffice/region/regionPrivince',
            cityUrl: 'http://' + backOfficeHost + '/rest/v1.0/backoffice/region/regionCity',
            cityAreaUrl: 'http://' + backOfficeHost + '/rest/v1.0/backoffice/region/regionCounty',
            villageUrl: 'http://' + backOfficeHost + '/rest/v1.0/mis/community/communityList',
            ajax: $http
        };
        $scope.cascading = new gObj.cascading(cascadData);
        $scope.cascading.paint($(".city-cascading")[0],true);




    }]).controller('communityImportCtrl', ['$scope','$http', '$location', function ($scope, $http, $location) {


        $scope.currentPage = 1;
        $scope.pageSize = 10;

        //菜单分页
        $scope.pagination = new pagination({currentPage:$scope.currentPage,pageSize: $scope.pageSize,
            url:'http://' + backOfficeHost + '/rest/v1.0/mis/community/communityImportRecord/:page/:size',
            ajax: $http,
            success:function(data){
                $scope.recordList = data.data.list;
                $scope.pageNumber = data.data.totalPage;
                $scope.count = data.data.count;
                //$('#count').text("共"+$scope.pageNumber+"页 有"+$scope.count+"数据");
            },
            error: function(err){
                $scope.communityList = null;
            },
            params: {}
        });

        //全选列表
        $scope.allSelected = function(){
            $scope.pagination.allSelected();
        };


        $scope.selectExcelFile = function (files) {

            if (!FileReader) alert("浏览器暂时不支持FileReader");
            $scope.excel = files[0];
        };



        // 导入小区
        $scope.import = function() {
            var formData = new FormData();
            if (!$scope.excel) {
                alert("未选择Excel文件！");
                return;
            }

            formData.append('excel', $scope.excel);
            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/community/communityImport', formData, {
                transformRequest: angular.identity, headers: {'Content-Type': "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}
            }).success(function (data) {
                $scope.pagination.selectPage(1);//插入成功显示第一页
                $('#doc-modal-import').modal("close");
                $('#loading').modal("close");
                alert("导入小区成功");
            }).error(function () {
                $('#loading').modal("close");
                alert("导入小区失败！");
            });
        };






        //修复线上小区
        $scope.modify = function(addData, target, index) {
            var formData = new FormData();
            if (!$scope.excel) {
                alert("未选择Excel文件！");
                return;
            }

            formData.append('excel', $scope.excel);
            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/community/communityModify', formData, {
                transformRequest: angular.identity, headers: {'Content-Type': undefined}
            }).success(function (data) {
                $scope.pagination.selectPage(1);//插入成功显示第一页
                $('#doc-modal-import').modal("close");
                $('#loading').modal("close");
                alert("导入小区成功");
            }).error(function () {
                $('#loading').modal("close");
                alert("导入小区失败！");
            });

        };

    }]).controller('communitySupplementCtrl', ['$scope','$http', '$location', function ($scope, $http, $location) {

        $scope.currentPage = 1;
        $scope.pageSize = 20;

        //分页
        $scope.pagination = new pagination({currentPage:$scope.currentPage,pageSize: $scope.pageSize,
            url:'http://' + backOfficeHost + '/rest/v1.0/mis/community/supplementList/:page/:size',
            ajax: $http,
            success:function(data){
                $scope.supplementList = data.data.list;
                $scope.pageNumber = data.data.totalPage;
                $scope.count = data.data.count;

                $scope.currentPage = $(".am-active").text();
                $scope.pagination.totalPage = data.data.totalPage;
                $scope.pagination.pageHeader($scope.pageNumber);
                $('#count').text("共"+$scope.pageNumber+"页 有"+$scope.count+"数据");
            },
            error: function(err){
                $scope.communityList = null;
            },
            params: {}
        });

        //全选列表
        $scope.allSelected = function () {
            $scope.pagination.allSelected();
        };

        //搜索
        $scope.search = function (temp) {

            var target = temp.target;
            $scope.pagination.currentPage = 1;
            $scope.currentPage = 1;


            var community = $scope.cascading.getVillageId(target);

            var body = {};
            if (community) body.community = community;
            if ($scope.status) body.status = $scope.status;

            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/community/supplementList/' + $scope.currentPage + '/' + $scope.pageSize, body, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {
                $scope.supplementList = data.data.list;
                $scope.pageNumber = data.data.totalPage;
                $scope.count = data.data.count;

                $scope.pagination.totalPage = data.data.totalPage;
                $scope.pagination.pageHeader($scope.pageNumber);
                $scope.pagination.searchParams = body;
            }).error(function (err) {
                alert(err);
            });

        };



        $scope.handleSupplement =  function (supplement, accept) {

            var body = {};
            if (accept) {
                body = {id: supplement.objId, status: true};
                body.name = supplement.desc;
                body.phone = supplement.phone;
                body.user = supplement.createdBy.objId;
                body.community = supplement.community.objId;
                body.supplyId = supplement.id;
                if (supplement.address)  body.address = supplement.address;
            } else {
                body = {id: supplement.objId, status: false,user : supplement.createdBy.objId,name:supplement.desc};
            }



            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/community/supplementStatusUpdate', body, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {
                if (data.result.status == 1) {
                    supplement.status = accept ? true:false;
                }else {
                    alert('请检查补充信息格式是否正确，信息不合法应拒绝！');
                }
            }).error(function (err) {
                alert(err);
            });
        };

        //级联框
        var cascadData = {
            provinceUrl: 'http://' + backOfficeHost + '/rest/v1.0/backoffice/region/regionPrivince',
            cityUrl: 'http://' + backOfficeHost + '/rest/v1.0/backoffice/region/regionCity',
            cityAreaUrl: 'http://' + backOfficeHost + '/rest/v1.0/backoffice/region/regionCounty',
            villageUrl: 'http://' + backOfficeHost + '/rest/v1.0/mis/community/communityList',
            ajax: $http
        };
        $scope.cascading = new gObj.cascading(cascadData);
        $scope.cascading.paint($(".city-cascading")[0],true);

    }]).controller('communityApply', ['$scope','$http', '$location', function ($scope, $http, $location) {

        $scope.currentPage = 1;
        $scope.pageSize = 15;

        //分页
        $scope.pagination = new pagination({currentPage:$scope.currentPage,pageSize: $scope.pageSize,
            url:'http://' + backOfficeHost + '/rest/v1.0/mis/community/applyList/:page/:size',
            ajax: $http,
            success:function(data){
                $scope.applyList = data.data.list;
                $scope.pageNumber = data.data.totalPage;
                $scope.count = data.data.count;
                //console.debug(data.data.list);
                $scope.currentPage = $(".am-active").text();
                $scope.pagination.totalPage = data.data.totalPage;
                $scope.pagination.pageHeader($scope.pageNumber);
                $('#count').text("共"+$scope.pageNumber+"页 有"+$scope.count+"数据");
            },
            error: function(err){
                $scope.applyList = null;
            },
            params: {}
        });

        //搜索
        $scope.applySearch = function () {

            var opt = {};
            if ($scope.communityName) opt.communityName = $scope.communityName;
            if ($scope.status) opt.status = Number($scope.status);

            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/community/applyList/' + 1 + '/' + $scope.pageSize, opt, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {
                $scope.applyList = data.data.list;
                $scope.pageNumber = data.data.totalPage;
                $scope.count = data.data.count;

                $scope.currentPage = $(".am-active").text();
                $scope.pagination.totalPage = data.data.totalPage;
                $scope.pagination.pageHeader($scope.pageNumber);

            }).error(function (err) {
                alert(err);
            });

        };

        $scope.passShow = function(apply) {

            var opt = {
                user: apply.user.objId,
                type: apply.type
            };
            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/community/applyPassCheck', opt, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {

                if (data.result.status == 1) {

                    if (data.data) {
                        $scope.passApply = apply;
                        $scope.passApply.msg = "你申请的<" + apply.communityName + ">小区成功开通啦,人多才能嗨起来哦，快召唤小伙伴吧！在这里建立属于你自己的邻里圈，随时随地掌握小区新动态！";
                        $('#doc-modal-pass').modal({target: '#doc-modal-pass', width: 600, height: 350});
                    }else{
                        alert("父母小区申请通过失败!\n父母小区未创建或申请人还未绑定父母小区!");
                    }

                } else {
                    $('#doc-modal-pass').modal('close');
                    alert("小区审批通过失败！");
                    //$scope.pagination.selectPage($scope.currentPage);
                }

            }).error(function (err) {
                alert('系统错误，请联系管理员！')
            });


        };


        $scope.rejectShow = function(apply) {
            $scope.rejectApply = apply;
            $scope.rejectApply.msg = "很遗憾你申请的<"+apply.communityName+">小区没有通过，也许是你的小区信息名字不正确或不存在哦，赶快去看看吧！";
            $('#doc-modal-reject').modal({target: '#doc-modal-reject', width: 600, height: 350});
        };

        //请求通过
        $scope.applyPass = function(apply){

            //console.debug(apply);

            var opt = {
                applyId : apply.objId,
                status : 1,
                user: apply.user.objId,
                phone: apply.user.mobilePhone,
                msg :  apply.msg,
                type : apply.type
            };
            console.debug(opt);

            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/community/applyPass', opt,{
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {

                if (data.result.status == 1) {
                    apply.status = 1;
                    $('#doc-modal-pass').modal('close');
                    alert("小区审批通过成功！");
                }else {
                    $('#doc-modal-pass').modal('close');
                    alert("小区审批通过失败！");
                    //$scope.pagination.selectPage($scope.currentPage);
                }

            }).error(function (err) {
                $('#doc-modal-pass').modal('close');
                alert("小区审批通过失败！");
                //$scope.pagination.selectPage($scope.currentPage);
            });


        };

        //请求拒绝
        $scope.applyReject = function(apply){

            var opt = {
                applyId : apply.objId,
                user: apply.user.objId,
                phone: apply.user.mobilePhone,
                status : -1,
                msg : apply.msg
            };

            console.debug(opt);

            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/community/applyReject', opt,{
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {

                if (data.result.status == 1) {
                    apply.status = -1;
                    $('#doc-modal-reject').modal('close');
                    alert("小区审批拒绝成功！");
                }else {
                    $('#doc-modal-reject').modal('close');
                    alert("小区审批拒绝失败！");
                    //$scope.pagination.selectPage($scope.currentPage);
                }

            }).error(function (err) {
                $('#doc-modal-reject').modal('close');
                alert("小区审批拒绝失败！");
                //$scope.pagination.selectPage($scope.currentPage);
            });

        };

    }]);

